/**
 node根据数据结构去生成一个项目文件

**/


const fs = require('fs')
const path = require('path')

let initData = {
	"project": 'myDemo1',
	"data": [
       {
       	"type": "dir",
       	"name": 'js'
       },
       {
       	"type": "dir",
       	"name": 'imges'
       },
       {
       	"type": "dir",
       	"name": 'css'
       },
       {
       	"type": "file",
       	"name": 'index.html'
       }
   
	]
}
const file = `<!DOCTYPE html>
	<html>
	<head>
	  <meta charset="UTF-8">
	  <title>Document</title>
	</head>
	<body>
	  <div>欢迎访问</div>
	</body>
	</html>
`;

fs.mkdir(path.join(__dirname, `../${initData.project}`), err => {
	if(err) return
  initData.data.forEach(item => {
  	if (item.type === 'dir') {
  		fs.mkdirSync(path.join(__dirname, `../${initData.project}`, item.name))
  	} else {
  		fs.writeFile(path.join(__dirname, `../${initData.project}`, item.name), file)
  	}
  })
})